/**
 * @file shell_port.c
 * @author Letter (NevermindZZT@gmail.com)
 * @brief 
 * @version 0.1
 * @date 2019-02-22
 * 
 * @copyright (c) 2019 Letter
 * 
 */

#include "shell.h"
#include "shell_port.h"
#include "bsp_debug_usart.h"

Shell shell;
char shellBuffer[512];

/**
 * @brief shell写数据函数原型
 *
 * @param data 需写的字符数据
 * @param len 需要写入的字符数
 *
 * @return unsigned short 实际写入的字符数量
 */
signed short userShellWrite(const char *data, unsigned short len)
{
    debug_usart_send_data((uint8_t *)data,len);
    return len;
}

/**
 * @brief shell读取数据函数原型
 *
 * @param data shell读取的字符
 * @param len 请求读取的字符数量
 *
 * @return unsigned short 实际读取到的字符数量
 */
signed short userShellRead(char *data, unsigned short len)
{
    while (lwrb_read(&debug_usart_rx_dma_ringbuff,data,len) == 0)
    {
        xSemaphoreTake(debug_usart_rx_sem,portMAX_DELAY);
    }
    return len;
}

/**
 * @brief 用户shell初始化
 * 
 */
void userShellInit(void)
{
    shell.write = userShellWrite;
    shell.read = userShellRead;
    shellInit(&shell, shellBuffer, 512);
}
